<script>
	import { mapState, mapMutations} from 'vuex'
	import {showModal} from './common/js/util'
	import * as systemApi from './interface/common/system.js'
	import * as authUserApi from './interface/auth/authUserApi.js'
	import life from '@/components/pai-mp-payment/tools/lifecycle.js'
	export default {
		onLaunch: function() {
			const v = this
			let menuButtonObject = wx.getMenuButtonBoundingClientRect();
			// 微信标题右侧胶囊按钮距顶部高度
			if (menuButtonObject.top) v.$store.commit("setMenuBtnTop", menuButtonObject.top)
			wx.getSystemInfo({
				success: res => {
					v.$store.commit("setStatusBarHeight", res.statusBarHeight)
					v.$store.commit("setPageWidth", res.screenWidth)
					// 页面高度,不包含tabbar(50px)的高度
					v.$store.commit("setPageHeight", res.windowHeight)
					v.$store.commit("setScreenHeight", res.screenHeight)
				}
			})
			v.getApplyForm()
			v.checkAppUpdate()
			v.$store.commit("setEnvVersion", wx.getAccountInfoSync().miniProgram.envVersion || '')
		},
		onShow: function(options) {
			this.resetState()
			life.onShow(option)
			// 粤信签小程序调用成功后会带token返回到小程序上,需进行用户自助登录

		},
		onHide: function() {
			console.log('App Hide')
			life.onHide()
		},
		methods: {
			...mapMutations(['resetState']),
			getApplyForm () {
				const v = this
				systemApi.getDictList('apply_form').then(({ data }) => {
					v.$store.commit("setApplyForm", data)
				})
			},

			checkAppUpdate () {
			    const updateManager = wx.getUpdateManager()
			    if (updateManager) {
					updateManager.onCheckForUpdate((res) => {
						// 请求完新版本信息的回调
					})
					updateManager.onUpdateReady(() => {
						showModal('更新提示', `新版本已经准备好，是否重启应用？`, true, '确定', '取消', (res) => {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate()
						}, (res) => {
							return
						})
					})
					updateManager.onUpdateFailed(() => {
			        // 新版本下载失败
					})
			    }
			  }
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import url("./common/expand/plugins/ali-font/iconfont.css");
	@import "@/uni_modules/uview-ui/index.scss";
	@import url("./common/css/common.css");
	@import url("./common/expand/plugins/tailwind/tailwind.css");

	uni-modal .uni-modal {
		border-radius: 8px !important;
	}

	uni-toast {
		font-size: 14px;
	}

	uni-toast .uni-icon_toast {
	    margin: 15px 0 6px;
	}

	uni-toast .uni-icon_toast.uni-icon-success-no-circle:before {
	    font-size: 35px;
	}
</style>
